import {
  DETAIL_OBJ,// 商品详情数据
  MODIFY_OBJ,// 修改商品规格
  USER_INFO,//用户信息
  GET_USER_INFO,//获取缓存用户信息
  DELETE_USER_INFO,//删除缓存用户信息
  
  HOME_CASUAL,
  HOME_NAV,
  HOME_SHOP_LIST,
  RECOMMEND_SHOP_LIST,
  SEARCH_GOODS,
  RESET_USER_INFO,
  CART_GOODS_LIST
} from './mutation-types'

// 引入本地存储
import { CartModel } from '../common/CartModel'
let cartmodel = new CartModel()
export default {
  /**
   *  商品详情数据
   */
  [DETAIL_OBJ](state, {obj1,arr}) {
	  console.log(obj1)
	  //商品详情进入
	  if(typeof obj1 === 'object'){
		  state.SizeList = obj1;
	  //购物车订单进入
	  }else if(typeof obj1 === 'number'){
		  cartmodel.getCartData(res =>{
			  res.forEach(item =>{
				  if(item.goodsId === obj1.toString()){
						state.SizeList = item;
						state.arrP = arr;
				  }
			  })
		  })
	  }
  },
  /**
   *  改修商品详情规格
   */
  [MODIFY_OBJ](state, {index,idx}){
	  state.arrP.splice(index, 1, idx);
	  console.log(state.SizeList)
  },
  /**
   *  用户信息
   */
  [USER_INFO](state, {userInfo}){
	  cartmodel.localSetUserinfo(userInfo)
  },
  /**
   *  获取缓存用户信息
   */
  [GET_USER_INFO](state){
  	  state.userInfo = cartmodel.localgetUserinfo()
  }, 
  /**
   *  删除缓存用户信息
   */
  [DELETE_USER_INFO](state){
  	  cartmodel.localRemoveUserinfo()
  }, 
  [HOME_CASUAL](state, {homecasual}) {
    state.homecasual = homecasual;
  },

  [HOME_NAV](state, {homenav}) {
    state.homenav = homenav;
  },

  [HOME_SHOP_LIST](state, {homeshoplist}) {
    state.homeshoplist = homeshoplist;
  },

  [RECOMMEND_SHOP_LIST](state, {recommendshoplist}) {
    state.recommendshoplist = state.recommendshoplist.concat(recommendshoplist);
  },

  [SEARCH_GOODS](state, {searchgoods}) {
    state.searchgoods = searchgoods;
  },

  [CART_GOODS_LIST](state, {cartgoods}) {
    state.cartgoods = cartgoods;
  },
}
